﻿using UnityEngine;
using System.Collections;

public static partial class Extensions
{
    /// <summary>
    /// 刚体所受到的经过gravityScale缩放后的重力
    /// </summary>
    /// <param name="rigidbody"></param>
    /// <returns></returns>
    public static float ScaledGravity(this Rigidbody2D rigidbody)
    {
        return rigidbody.gravityScale * Mathf.Abs(Physics2D.gravity.y);
    }

    /// <summary>
    /// 计算自由落体时的速度
    /// </summary>
    public static float FFMEndSpeed(this Rigidbody2D rigidbody, float freeFallHight)
    {
        return Mathf.Sqrt(2 * rigidbody.ScaledGravity() * freeFallHight);
    }
}